#include <list>
#include <string>
#include <cstdlib>
using namespace std;
#include "game.h"
#ifdef WINDOW_MODE
#include "window.h"
#else
#include "console.h"
#endif
#include "out.h"
#include "in.h"
#include "net.h"

extern "C" {
#include <curses.h>
}

#include "console.h"
using namespace std;

void TView::blit(){

}

void TView::pan(int diff_x, int diff_y){

}

TView::TView(){
 Screen=new TScreen();
}

TView::~TView(){

}

void TScreen::draw_unit(TUnit* unit) {
 int pair_id;
 switch (unit->owner->state){
  case STATE_SELF: pair_id=PAIR_SELF; break;
  case STATE_ALLY: pair_id=PAIR_ALLY; break;
  case STATE_ENEMY: pair_id=PAIR_ENEMY; break;
  case STATE_NEUTRAL: pair_id=PAIR_NEUTRAL; break;
 }
 draw_char(unit->x-view->offset_x, unit->y-view->offset_y, unit->type, pair_id);
}

void TScreen::draw_char(int x, int y, char type, int pair_id){
 if (use_colors)
  attron(COLOR_PAIR(pair_id));
 mvaddch(x, y, type);
 if (use_colors)
  attroff(COLOR_PAIR(pair_id));

}

void TScreen::draw_building(TBuilding * Building) {
 
}

void TScreen::draw_menu(int x, int y, TMenuItems* items) {
 
}

void TScreen::blit() {
 refresh();
}

TScreen::TScreen() {
 TScreen(80, 40);
}

TScreen::TScreen(int width, int height) {
 initscr();
 cbreak();
 keypad(stdscr, TRUE);
 noecho();
 if(has_colors() != FALSE){
  start_color();
  use_colors=true;
  init_pair(PAIR_SELF, COLOR_SELF, BG_NORMAL);
  init_pair(PAIR_ALLY, COLOR_ALLY, BG_NORMAL);
  init_pair(PAIR_ENEMY, COLOR_ENEMY, BG_NORMAL);
  init_pair(PAIR_NEUTRAL, COLOR_NEUTRAL, BG_NORMAL);
 }
}

void TScreen::blit(int x, int y, int width, int height){
 
}
void TScreen::print(int x, int y, string text){
 mvprintw(y, x, text.c_str());
}

TKeyboard::TKeyboard() {
 
}
